<template>
  <view class="preview-page">
    <nav-header title="简历预览"></nav-header>

    <view class="content" :style="{ paddingTop: statusBarHeight + 44 + 'px' }">
      <ResumePreview :data="content" />
      
      <view class="action-buttons">
        <button class="action-btn edit-btn" @click="goToEdit">
          <text class="btn-icon">✏️</text>
          <text>继续编辑</text>
        </button>
        <button class="action-btn share-btn" @click="exportPDF">
          <text class="btn-icon">📄</text>
          <text>导出PDF</text>
        </button>
      </view>
    </view>
  </view>
</template>

<script setup>
import { ref, reactive, computed, onMounted } from 'vue'
import { useResumeStore } from '@/store/resume.js'
import NavHeader from '@/components/nav-header.vue'
import ResumePreview from '@/components/ResumePreview.vue'
import {
		onLoad
	} from '@dcloudio/uni-app'
import { getPreviewMarkdown } from '@/api/preview.js'
import env from '@/env'
import { useAuthStore } from '@/store/index';
	
const authStore = useAuthStore();
const resumeStore = useResumeStore()
const statusBarHeight = ref(20)
const sharePopup = ref(null)
const saveSuccessPopup = ref(null)
const currentColorScheme = ref(0)
const resumeData = ref({})
const content = ref('')

// 颜色配色方案
const colorSchemes = [
  { primary: '#5ac725', secondary: '#e6f7e1', background: '#ffffff' },
  { primary: '#2196f3', secondary: '#e3f2fd', background: '#ffffff' },
  { primary: '#ff5722', secondary: '#fbe9e7', background: '#ffffff' },
  { primary: '#9c27b0', secondary: '#f3e5f5', background: '#ffffff' },
  { primary: '#3f51b5', secondary: '#e8eaf6', background: '#ffffff' },
  { primary: '#009688', secondary: '#e0f2f1', background: '#ffffff' },
]

// 当前配色
const templateColors = computed(() => {
  return colorSchemes[currentColorScheme.value]
})

// 简历数据
const resume = computed(() => {
  return resumeStore.resume || {}
})

// 内容

onMounted(() => {
  // 获取状态栏高度
  const systemInfo = uni.getSystemInfoSync()
  statusBarHeight.value = systemInfo.statusBarHeight
})

onLoad(async (options) => {
  console.log('options', options);
  if (options.id) {
    getContent(options.id)
  }
})

const getContent = async (id) => {
  const res = await getPreviewMarkdown(id)
  console.log('res', res);
  content.value = res.msg
  
  console.log('简历内容:', content.value);
}

// 格式化时间显示
const formatTime = (timeStr) => {
  if (!timeStr) return ''
  return timeStr.replace(/(\d{4})-(\d{2})/, '$1年$2月')
}

// 返回编辑页
const goToEdit = () => {
  uni.navigateBack()
}

// 导出PDF功能
const exportPDF = () => {
  uni.showLoading({ title: '正在生成PDF...' })
  
  setTimeout(() => {
    uni.hideLoading()
    
    uni.showModal({
      title: '导出提示',
      content: 'PDF文件已生成，可在"我的简历"中查看',
      showCancel: false
    })
  }, 1500)
}
</script>

<style lang="scss" scoped>
.preview-page {
  min-height: 100vh;
  background-color: #F8F8F8;
  
  .content {
    padding: 16px;
    padding-bottom: 30px;
  }
  
  .preview-container {
    background-color: #FFFFFF;
    border-radius: 12px;
    padding: 16px;
    margin-bottom: 20px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
    max-height: 65vh;
    overflow-y: auto;
  }
  
  .resume-document {
    background-color: #FFFFFF;
    font-family: 'Helvetica Neue', Arial, sans-serif;
    
    .resume-header {
      padding: 20px;
      display: flex;
      align-items: center;
      color: #FFFFFF;
      border-radius: 8px;
      margin-bottom: 16px;
      
      .avatar-container {
        width: 70px;
        height: 70px;
        border-radius: 50%;
        overflow: hidden;
        margin-right: 16px;
        border: 2px solid rgba(255, 255, 255, 0.8);
        
        .avatar {
          width: 100%;
          height: 100%;
        }
      }
      
      .header-info {
        flex: 1;
        
        .name {
          font-size: 22px;
          font-weight: bold;
          margin-bottom: 8px;
          display: block;
        }
        
        .contact-info {
          display: flex;
          flex-wrap: wrap;
          
          .contact-item {
            font-size: 13px;
            margin-right: 12px;
            display: flex;
            align-items: center;
            
            .icon {
              margin-right: 4px;
            }
          }
        }
      }
    }
    
    .resume-section {
      margin-bottom: 20px;
      
      .section-title {
        font-size: 18px;
        font-weight: 600;
        margin-bottom: 12px;
        padding-bottom: 6px;
        border-bottom: 1px solid #eee;
      }
      
      .section-content {
        padding: 0 4px;
        
        .summary-text {
          font-size: 14px;
          color: #666;
          line-height: 1.5;
        }
        
        .skills-list {
          display: flex;
          flex-wrap: wrap;
          
          .skill-item {
            padding: 8px 12px;
            border-radius: 6px;
            border: 1px solid;
            margin-right: 10px;
            margin-bottom: 10px;
            display: flex;
            flex-direction: column;
            align-items: center;
            
            .skill-name {
              font-size: 14px;
              margin-bottom: 5px;
            }
            
            .skill-level {
              display: flex;
              
              .level-dot {
                width: 6px;
                height: 6px;
                border-radius: 50%;
                margin: 0 2px;
              }
            }
          }
        }
        
        .experience-item {
          margin-bottom: 16px;
          
          .experience-header {
            display: flex;
            justify-content: space-between;
            margin-bottom: 6px;
            
            .title-container {
              display: flex;
              flex-direction: column;
              
              .experience-title {
                font-size: 16px;
                font-weight: 500;
                color: #333;
              }
              
              .experience-subtitle {
                font-size: 14px;
                color: #666;
              }
            }
            
            .experience-time {
              font-size: 13px;
              color: #888;
              white-space: nowrap;
            }
          }
          
          .experience-content {
            .description-text {
              font-size: 14px;
              color: #666;
              line-height: 1.5;
            }
          }
          
          .project-link {
            margin-top: 8px;
            
            .link-text {
              font-size: 13px;
              color: #2196f3;
            }
          }
        }
      }
    }
  }
  
  .action-buttons {
    display: flex;
    margin-bottom: 20px;
    
    .action-btn {
      flex: 1;
      height: 44px;
      display: flex;
      align-items: center;
      justify-content: center;
      border-radius: 22px;
      font-size: 15px;
      
      .btn-icon {
        margin-right: 6px;
      }
    }
    
    .edit-btn {
      background-color: #f5f5f5;
      color: #666;
      margin-right: 12px;
    }
    
    .share-btn {
      background-color: #5ac725;
      color: #FFFFFF;
    }
  }
  
  .template-colors {
    background-color: #FFFFFF;
    border-radius: 12px;
    padding: 16px;
    
    .colors-title {
      font-size: 16px;
      font-weight: 500;
      margin-bottom: 12px;
      display: block;
    }
    
    .color-options {
      display: flex;
      flex-wrap: wrap;
      
      .color-option {
        width: 36px;
        height: 36px;
        border-radius: 50%;
        margin-right: 12px;
        margin-bottom: 8px;
        cursor: pointer;
        
        &.active {
          transform: scale(1.1);
          box-shadow: 0 0 0 2px #FFF, 0 0 0 4px currentColor;
        }
      }
    }
  }
  
  .share-options {
    background-color: #FFFFFF;
    border-radius: 12px 12px 0 0;
    
    .share-header {
      display: flex;
      justify-content: space-between;
      align-items: center;
      padding: 16px;
      border-bottom: 1px solid #f0f0f0;
      
      .share-title {
        font-size: 16px;
        font-weight: 500;
      }
      
      .close-btn {
        font-size: 24px;
        color: #999;
        width: 36px;
        height: 36px;
        display: flex;
        align-items: center;
        justify-content: center;
      }
    }
    
    .share-content {
      display: flex;
      padding: 20px 16px;
      
      .share-item {
        display: flex;
        flex-direction: column;
        align-items: center;
        margin-right: 24px;
        
        .share-icon {
          width: 50px;
          height: 50px;
          border-radius: 12px;
          background-color: #f5f5f5;
          display: flex;
          align-items: center;
          justify-content: center;
          font-size: 24px;
          margin-bottom: 8px;
        }
        
        .share-name {
          font-size: 12px;
          color: #666;
        }
      }
    }
  }
}
</style> 